package com.mymoney.persistence.managers;

import java.util.List;

import com.mymoney.beans.StoreBean;
import com.mymoney.exceptions.MyMoneyException;
import com.mymoney.persistence.PersistenceContext;

/**
 * 
 * @author yavor.gologanov
 *
 */
public class StoreManager extends AbstractBeanManager<StoreBean> {

	public StoreManager(PersistenceContext persistenceContext) {
		super(persistenceContext);
	}

	
	@Override
	public void add(StoreBean store) {

		if(store != null)
		{
			store.setCode(System.currentTimeMillis());
			storeEntity(store);
		}
	}


	@Override
	public List<StoreBean> list() throws MyMoneyException {
		
		String queryString = "select d from StoreBean d";
		List<StoreBean> stores = findAllEntities(queryString, -1,(Object[]) null);
		return stores;
	}


	@Override
	public StoreBean getByCode(long code) throws MyMoneyException {

		return getBy("select p from StoreBean p where p.code = :code", code, "code");
	}


	@Override
	public StoreBean getById(Integer id) throws MyMoneyException {

		return getBy("select p from StoreBean p where p.id = :id", id, "id");
	}


	@Override
	public StoreBean getByName(String name) throws MyMoneyException {

		return getBy("select p from StoreBean p where p.name = :name", name, "name");
	}


	@Override
	public void update(StoreBean first, StoreBean second)
			throws MyMoneyException {
		throw new MyMoneyException("Method is not implemented!");
		
	}


	@Override
	public void update(StoreBean entity, long code) throws MyMoneyException {
		throw new MyMoneyException("Method is not implemented!");
		
	}


	@Override
	public void update(StoreBean entity, Integer id) throws MyMoneyException {
		throw new MyMoneyException("Method is not implemented!");
		
	}


	@Override
	public void update(StoreBean entity, String name) throws MyMoneyException {
		throw new MyMoneyException("Method is not implemented!");
		
	}

}
